package com.gin.retrofit.utils

import com.fasterxml.jackson.databind.ObjectMapper
import com.gin.retrofit.factory.QueryParameterConverterFactory
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory

/**
 * @author BX-Gin
 * @since 2024/3/9 17:20
 */
class RetrofitUtils {
    companion object {
        /**
         * 创建Retrofit实例
         * @param client OkHttpClient
         * @param baseUrl String
         * @return Retrofit
         */
        @JvmStatic
        fun obtainRetrofit(client: OkHttpClient, baseUrl: String, objectMapper: ObjectMapper): Retrofit {
            return Retrofit.Builder()
                .client(client)
                .baseUrl(baseUrl)
                .addConverterFactory(JacksonConverterFactory.create(objectMapper))
                .addConverterFactory(QueryParameterConverterFactory())
                .build()
        }
    }
}